import Vue from 'vue'
import Router from 'vue-router'
import index from '@/components/index'
import cart from '@/components/cart'
import item from '@/components/item'
import detail from '@/components/detail'
import mytest from '@/components/mytest'
import test from '@/components/test'
import reg from '@/components/reg'
import login from '@/components/login'
import myprofile from '@/components/myprofile'
import activity from '@/components/activity'
import examination_login from '@/components/examination_login'
import examination_register from '@/components/examination_register'
import kaoshi from '@/components/kaoshi'
import addgoods from '@/components/addgoods'
import editgood from '@/components/editgood'
import addgoods_exam from '@/components/addgoods_exam'
import goodlist from '@/components/goodlist'
import guanzhu from '@/components/guanzhu'
import search from '@/components/search'
import fuzujian from '@/components/fuzujian'
import tongxun from '@/components/tongxun'

Vue.use(Router)

var routes = [
        {
          path:'/',
          name:'index',
          component:index
        },
        {
          path:'/cart',
          name:'cart',
          component:cart
        },
        {
          path:'/item',
          name:'item',
          component:item
        },
        {
          path:'/detail',
          name:'detail',
          component:detail
        },
        {
          path:'/mytest',
          name:'mytest',
          component:mytest
        },
        {
          path:'/test',
          name:'test',
          component:test
        },
        {
          path:'/reg',
          name:'reg',
          component:reg
        },
        {
          path:'/login',
          name:'login',
          component:login
        },
        {
          path:'/activity',
          name:'activity',
          component:activity
        },
        {
          path:'/addgoods',
          name:'addgoods',
          component:addgoods
        },
        {
          path:'/editgood',
          name:'editgood',
          component:editgood
        },
        
        {
          path:'/myprofile',
          name:'myprofile',
          component:myprofile,
          beforeEnter: (to, from, next) => {
            // 判断用户是否登录
            if (localStorage.getItem('username')) {
              // console.log('已登录');
              next();
            }
            else{
              // console.log('未登录');
              next('/login');
            }
          }
        },
        {
          path:'/exlogin',
          name:'examination_login',
          component:examination_login
        },
        {
          path:'/exreg',
          name:'examination_register',
          component:examination_register
        },
        {
          path:'/kaoshi',
          name:'kaoshi',
          component:kaoshi
        },
        {
          path:'/addgoods_exam',
          name:'addgoods_exam',
          component:addgoods_exam
        },
        {
          path:'/goodlist',
          name:'goodlist',
          component:goodlist
        },
        {
          path:'/guanzhu',
          name:'guanzhu',
          component:guanzhu
        },
        {
          path:'/search',
          name:'search',
          component:search
        },
        {
          path:'/fuzujian',
          name:'fuzujian',
          component:fuzujian
        },
        {
          path:'/tongxun',
          name:'tongxun',
          component:tongxun
        },
]

export default new Router({
  routes:routes,
  mode:'history'   /*hash*/
})
